import os
import base64
import httpx

from fastapi import FastAPI
from langchain.chat_models import AzureChatOpenAI
from langchain_core.messages import SystemMessage, HumanMessage
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langserve import add_routes

os.environ["http_proxy"] = "127.0.0.1:7890"
os.environ["https_proxy"] = "127.0.0.1:7890"
os.environ["LANGCHAIN_TRACING_V2"] = "true"
os.environ["LANGCHAIN_API_KEY"] = "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"

os.environ["OPENAI_API_BASE"] = "http://menshen.test.xdf.cn"
os.environ["OPENAI_API_KEY"] = "c8575027653b42b1b47747f0b4ab135b"
os.environ["OPENAI_API_TYPE"] = "azure"
os.environ["OPENAI_API_VERSION"] = "2023-05-15"

llm = AzureChatOpenAI(
    deployment_name="gpt-4o",
    model_name="gpt-4o",
    temperature=0)

image_url = 'https://pic.rmb.bdstatic.com/bjh/down/6yx1y8Qn3nK4C1CPAoWvjQ1a16ed522eeb235481b68b15310dadf2.jpg?for=bg'
msg = HumanMessage(
    content=[
        {'type': 'text', 'text': '请用中文翻译这段图片内容,并简要的概括一下'},
        {'type': 'image_url', 'image_url': {'url': image_url}}
    ]
)

resp = llm.invoke([msg])
print(resp)